<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@ include file="/_taglib.jsp" %>
<script type="text/javascript">
function modifyPassword(form){
	/*改用jquery.validate
	if ($("#new_password1").val() != $("#new_password").val() ){
		alert('<j:i18n key="admin.common.errorMsg.fail.user.2"/>');
		return false;
	}
	*/
	return ajaxFormSubmit(form);
}

$().ready(function(){
	$("#form1").validate({
		rules:{
			old_password : "required",
			new_password : {
				required : true,
				minlength : 6
			},
			new_password1 : {
				required : true,
				minlength : 6,
				equalTo : "#new_password"
			}
		},
		messages:{
			old_password : "必填",
			new_password : {
				required : "必填",
				minlength : "不少于6个字符"
			},
			new_password1 : {
				required : "必填",
				minlength : "不少于6个字符",
				equalTo : "两次输入需一致"
			}
		}
	});
});

</script>

<%@ include file="/_navbar.jsp" %>

<section class="content">
	<div class="container" id="data-container">
		<div class="col-md-11">
			<!-- Custom Tabs -->
			<div class="nav-tabs-custom">
			    <ul class="nav nav-tabs">
			        <li class="active"><a href="#tab_1" data-toggle="tab"><strong><j:i18n key="admin.profile.mdf_pwd"/></strong></a></li>
			        <li><a href="#tab_2" data-toggle="tab"><strong><j:i18n key="admin.profile.mdf_pfl"/></strong></a></li>
			    </ul>
			    <div class="tab-content">
			        <div class="tab-pane active" id="tab_1">
			        	<div style="background-color:#FFF7D4;">
							<form id="form1" role="form" action="sys/user/modifyPassword" method="post" onsubmit="return modifyPassword(this)">			        	
								<input type="hidden" "user__id" name="user.id" value="${user.id}">
								<div class="box">
									<div class="box-body">
										<div class="row">
											<div class="col-xs-10">
												<!-- text input -->
												<div class="form-group">
													<label>旧密码</label> 
													<input type="password" class="form-control"
														id="old_password"
														name="old_password"
														placeholder="Enter ...">
												</div>
												<!-- text input -->
												<div class="form-group">
													<label>新密码</label> 
													<input type="password" class="form-control"
														id="new_password"
														name="new_password"
														placeholder="Enter ...">
												</div>
												<!-- text input -->
												<div class="form-group">
													<label>再输入一次</label> 
													<input type="password" class="form-control"
														id="new_password1"
														name="new_password1"
														placeholder="Enter ...">
												</div>
											</div>
										</div>
									</div>
									<div class="box-footer" align="center">
										<button type="submit" class="btn btn-primary" style="postion: absolute; left: 45%;">
											<j:i18n key="admin.button.submit"/>
										</button>
									</div>									
								</div>
							</form>				        	
						</div>
					</div>
					<div class="tab-pane" id="tab_2">
						<div style="background-color:#FFF7D4;">
							<form id="form2" class="required-validate" role="form" action="sys/user/update" method="post" onsubmit="return ajaxFormSubmit(this,'sys/user/profile/${user.id}')">
								<input type="hidden" "user__id" name="user.id" value="${user.id}">
								<!-- general form elements disabled -->
								<div class="box">
									<div class="box-body">
				
										<div class="row">
											<div class="col-xs-3">
												<!-- text input -->
												<div class="form-group">
													<label>姓名</label> 
													<input type="text" class="form-control required"
														id="user__realName"
														name="user.realName"
														value="${user.realName}"
														placeholder="Enter ...">
												</div>
											</div>
											<div class="col-xs-3">
												<!-- text input -->
												<div class="form-group">
													<label>邮箱</label> 
													<input type="text" class="form-control email"
														id="user__email"
														name="user.email"
														value="${user.email}"
														placeholder="Enter ...">
												</div>
											</div>
											<div class="col-xs-3">
												<!-- text input -->
												<div class="form-group">
													<label>手机</label> 
													<input type="text" class="form-control"
														id="user__mobile"
														name="user.mobile"
														value="${user.mobile}"
														placeholder="Enter ...">
												</div>
											</div>
											
										</div>
										<div class="row">
											<div class="col-xs-12">
												<!-- text input -->
												<div class="form-group">
													<label>备注</label> 
													<textarea class="form-control" rows="3" 
														id="user__remark"
														name="user.remark"
														placeholder="Enter ...">${user.remark}</textarea>
												</div>
											</div>
										</div>
										<!-- 
										<div class="row">
											<div class="col-xs-12">						
												<div class="form-group jfk-center-1">
													<label>头像</label>
													<img id="img-pic" src="http://placehold.it/350x300" alt="..." class="margin jfk-center-1" height="100">
													<div class="jfk-center-1" style="float:left">
				                                          <input type="file" id="uploadFileInput" name="uploadFileInput" style="float:left">
				                                          <input type="button" id="buttonUpload" onclick="return ajaxFileUpload('img-pic','user__picture');" value="上传"/>
				                                          <input type="button" id="buttonClear" onclick="return clearFileUpload('img-pic','user__picture');" value="清除"/>
				                                    </div>
												</div>		
											</div>
										</div>
										 -->
										<div class="row">
											<div class="col-xs-12">						
												<div class="form-group jfk-center-1">
													<label>头像</label>
				                                    <input type="hidden" id="picture" name="user.picture" value="${user.picture}">
													<c:choose>
														<c:when test="${empty user.picture}">
															<img id="imgUrl_user_picture" src="http://placehold.it/350x300" alt="..." class="margin jfk-center-1" height="100">
														</c:when>
														<c:otherwise>
															<a id="hrefUrl_user_picture" href="<j:kv key="${user.picture}" column="file_path" table="jfk_attachment_file"/>" target="_bank">
															<img id="imgUrl_user_picture" src="<j:kv key="${user.picture}" column="file_path" table="jfk_attachment_file"/>" alt="..." class="margin jfk-center-1" height="100">
															</a>
														</c:otherwise>
													</c:choose>
													<div>
														<a href="#" style="float:left" data-toggle="modal" data-target="#profile-upload-compose-modal" onclick="selectFile('jfk_user','${user.id}','uploadpic','imgUrl_user_picture','picture',null);">上传</a>
														<a href="#" style="float:right" onclick="clearFile('jfk_user','${user.id}','uploadpic','imgUrl_user_picture','picture','hrefUrl_user_picture',null)">清除</a>
													</div>
												</div>		
											</div>
										</div>

									</div>					<!-- /.box-body -->
									<div class="box-footer" align="center">
										<button type="submit" class="btn btn-primary" style="postion: absolute; left: 45%;">
											<j:i18n key="admin.button.submit"/>
										</button>
									</div>
								</div>				<!-- /.box -->
							</form>						
						
						</div>
						
					</div>
					
				</div>
			</div>
		</div>
	</div>
</section>

        <!-- COMPOSE MESSAGE MODAL -->
        <div class="modal fade" id="profile-upload-compose-modal" tabindex="-1" role="dialog" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title"><i class="fa fa-envelope-o"></i> 文件上传</h4>
                    </div>
                    <form action="#" method="post">
                        <div class="modal-body">
                            <div class="form-group">
                                <div class="input-group">
                                    <input type="file" id="uploadpic" name="uploadpic" class="form-control">
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer clearfix">
                            <button type="button" class="btn btn-success" onclick="return uploadFile();">上传</button>
                        </div>
                        
                     </form>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->

<%  
//    String path = request.getContextPath();  
//    String basePath = request.getScheme() + "://"  
//            + request.getServerName() + ":" + request.getServerPort()  
//            + path + "/";  
%> 

<%@ include file="/_edit_js.jsp" %>

<SCRIPT type="text/javascript">
	$(function (){
		kedit("user__remark",900);
	});
	
	
	var _tableName;
	var _dataId;
	var _uploadFileInput;
	var _imgUrl;
	var _attachmentId;
	var _callbackFunc;

	//由于共用对话框组件，所以打开对话框时，记录相关参数
	function selectFile(tableName,dataId,uploadFileInput,imgUrl,attachmentId,callbackFunc){
		_tableName = tableName;
		_dataId = dataId;
		_uploadFileInput = uploadFileInput;
		_imgUrl = imgUrl;
		_attachmentId = attachmentId;
		_callbackFunc = callbackFunc;
	}

	function uploadFile(){
		ajaxFileUploadByData(_tableName,_dataId,_uploadFileInput,_imgUrl,_attachmentId,_callbackFunc);
		$("#profile-upload-compose-modal").modal('hide');
	}

	function clearFile(_tableName,_dataId,_uploadFileInput,_imgUrl,_attachmentId,hrefUrl,callbackFunc){
		clearByData(_tableName,_dataId,_uploadFileInput,_imgUrl,_attachmentId,hrefUrl,callbackFunc);
	}
	
	

	
</SCRIPT>

